<template>
  <div class="Header">
    <van-nav-bar
      :title="title"
      :left-text="lefttext"
      :right-text="logingstatus"
      :left-arrow="leftarrow"
      @click-left="onClickLeft"
      @click-right="onClickRight($event)"
    />
  </div>
</template>

<script>
export default {
  name: "Header",
  data() {
    return {
      title: "我是标题",
      logingstatus: "登录",
      lefttext: "返回",
      leftarrow: true,
    };
  },
  methods: {
    checkLoginStatus:async function(){
      let response = await this.auth.trackSession()
      console.log(response)
    },
    onClickLeft: function () {
      this.$router.push({ name: "HomePage" });
      // this.$router.go(-1)
    },
    onClickRight: function (e) {
      console.log(e)
      // let text=e.srcElement.innerText
      // console.log(text)
      // this.checkLoginStatus()
    },
  },
  components: {},
  //create只会执行一次。。。
  mounted() {
    // console.log(this.$route);
    this.title = this.$route.path.slice(1);
    if (this.$route.path.slice(1) === "HomePage") {
      this.lefttext = "";
      this.leftarrow = false;
    }
    if (!this.$route.path.slice(1).indexOf("Share")) {
      this.title = this.$route.params.category;
    }
  },
  watch: {
    $route: {
      handler: function (newValue,oldValue) {
        if (!this.$route.path.slice(1).indexOf("Share")) {
          this.title=newValue.params.category;
        }
      },
    },
  },
};
</script>

<style scoped>
.Header {
  width: 100%;
  height: 50px;
  position: fixed;
  top: 0;
  z-index: 999999;
}
</style>
